package com.zhou.imaotai.mapper;


import com.zhou.imaotai.core.BaseMapperX;
import com.zhou.imaotai.core.LambdaQueryWrapperX;
import com.zhou.imaotai.entity.SysUserEntity;
import org.apache.ibatis.annotations.Select;


/**
 * @author lcz
 * @desc sys用户映射器
 * @mail lcz_0130@163.com
 * @date 2024/03/26
 */

public interface SysUserMapper extends BaseMapperX<SysUserEntity> {

    /**
     * 通过用户名查询用户
     *
     * @param userName
     * @return
     */
    @Select("select * from  sys_user  where user_name = #{userName} and del_flag = '0'")
    SysUserEntity selectUserByUserName(String userName);

    /**
     * 校验email是否唯一
     *
     * @param email 用户邮箱
     * @return 结果
     */
    default SysUserEntity checkEmailUnique(String email) {

        return selectOne(new LambdaQueryWrapperX<SysUserEntity>().eq(SysUserEntity::getEmail, email));
    }

    /**
     * 校验手机号码是否唯一
     *
     * @param phonenumber 手机号码
     * @return 结果
     */
    default SysUserEntity checkPhoneUnique(String phonenumber) {
        return selectOne(new LambdaQueryWrapperX<SysUserEntity>().eq(SysUserEntity::getPhonenumber, phonenumber));
    }

}
